package com.sgy.action;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sgy.common.ApiResult;
import com.sgy.netty.handler.UserInfoManager;
import com.sgy.util.StreamUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/im")
public class IMAction {

    private Logger log = LoggerFactory.getLogger(IMAction.class);

    @RequestMapping(value = "/pushMsg",method = RequestMethod.POST)
    public ApiResult chat(HttpServletRequest request){
        StringBuffer req = StreamUtil.getRequestBody(request);
        log.info("请求报文为:" + req.toString());
        JSONObject reqData = JSON.parseObject(req.toString());
        String sender = reqData.getString("sender");
        //Integer type = reqData.getInteger("type");
        String message = reqData.getString("message");
        String reciver = reqData.getString("reciver");
        UserInfoManager.p2p(sender,reciver,message);
        return ApiResult.success();
    }
}
